//index.js
//获取应用实例
import util from '../../utils/util.js';
import $ from '../../utils/ajax.js';
const app = getApp();

Page({
    data: {
       
        shopPage:{
            page:1,
            size:10,
            isRun:"",
            storeName:''
        },
        content:[],
        loginNav:0,
        value:'',
        text:true
        
    },
    onLoad(options) {
        
    },
    onShow() {
        this.shopPage()
    },
    goShop({ currentTarget: { dataset: { storeid}}}) {
        console.log(storeid)
      wx.navigateTo({
          url: `/pages/index/shopInformation/shopInformation?storeId=${storeid}`,
      })
    },
    navStep(e) {
        const num = Number(e.target.dataset.num)
        if(num === 0 ) {
            this.setData({
                text:true,
                ['shopPage.page']:1,
                ['shopPage.isRun']:0,
                ['shopPage.storeName']:'',
                loginNav:num,
                value:''
            },() => {
                this.shopPage()
            })
        }else if(num === 1) {
            this.setData({
                text: false,
                ['shopPage.page']: 1,
                ['shopPage.isRun']: 1,
                ['shopPage.storeName']: '',
                loginNav: num,
                value: ''
            },() => {
                this.shopPage()
            })
        }
        
       
        
    },
    details(e) {
        const value = e.detail.value;
        this.setData({
            value: value
        })
    },
    //搜索
    search() {
        console.log(this.data.value,"11111")
        this.setData({
            ['shopPage.storeName']: this.data.value,
            ['shopPage.page']:1
        },() => {
            this.shopPage()
        })
    },
    //下拉刷新
    onPullDownRefresh() {
    
        this.setData({
            value:'',
            ['shopPage.storeName']:'',
            ['shopPage.page']:1,

        },() => {
            this.shopPage()
        })
        wx.stopPullDownRefresh()
    },
    //上拉加载
    onReachBottom() {
        
        this.data.shopPage.page++,
        this.shopPage()
    },
    //拨打电话
    callPhone({ currentTarget: { dataset:{phone}}}) {
        wx.makePhoneCall({
            phoneNumber:phone
        })
    },
    //切换身份
    but() {
        wx.navigateTo({
            url:'/pages/apply/apply'
        })
    },
    //获取数据
    shopPage() {
        $.p(app.wxApp.url + 'agentincome/selectIndexStoreCommission', {
            page:this.data.shopPage.page,
            size: this.data.shopPage.size,
            isRun: this.data.loginNav,
            storeName: this.data.shopPage.storeName,
            roleId:6
        }, app.onStrart, (res) => {
            let data = this.data.content;
            if (res.data.page === 1) {
                data = res.data.list
            } else {
                res.data.list.map((item) => {
                    data.push({
                        ...item
                    })
                })
            }
            this.setData({
                content:data
            })
   
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    }

   
})